package com.rd.student.ruanjian.class3.gaochenxi.Exam;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.LinkedList;
import java.util.Scanner;

public class NumberOne {
   public static void main(String[] args) {
      String[] head = {"姓名", "语文成绩", "数学成绩", "总分"};
      LinkedList list1 = new LinkedList();
      LinkedList list2 = new LinkedList();
      LinkedList list3=new LinkedList();
      LinkedList info1 = Func(list1);
      LinkedList info2 = Func(list2);
      LinkedList info3=Func(list3);
      StringBuilder stringBuilder = new StringBuilder();
      for (int i = 0; i < head.length; i++) {
         stringBuilder.append(head[i] + " ");
      }
      stringBuilder.append("\n");
      for (Object obj1 : info1) {
         stringBuilder.append(obj1 + "    ");
      }
      stringBuilder.append("\n");
      for (Object obj2 : info2) {
         stringBuilder.append(obj2 + "    ");
      }
      stringBuilder.append("\n");
      for (Object obj3 : info3) {
         stringBuilder.append(obj3 + "    ");
      }

      try {
         File file = new File("Student.txt");
         FileWriter fileWriter = new FileWriter(file, true);
         if (!file.exists()) {
            file.createNewFile();
         }
         fileWriter.write(String.valueOf(stringBuilder));
         fileWriter.close();
      } catch (IOException e) {
         throw new RuntimeException(e);
      }
   }

   //为了输入学生信息的
   public static LinkedList Func(LinkedList list) {
         Scanner scanner = new Scanner(System.in);
         System.out.println("====================");
         System.out.println("请输入学生信息:");
         System.out.println("请输入姓名:");
         String next = scanner.next();
         list.add(next);
         System.out.println("请输入语文成绩:");
         int Chinese = scanner.nextInt();
         list.add(Chinese);
         System.out.println("请输入数学成绩:");
         int Math = scanner.nextInt();
         list.add(Math);
         list.add(Math + Chinese);
         System.out.println("====================");
      return list;
   }
}
